<template>
  <div class="hello">
    <nav>
      <a class="nav-zuo" href="#/goumai">
          <i class="fa fa-angle-left"></i>
      </a> 待收货
    </nav>
    
    <div class="dizhi">
      <ul>
        <li v-for="(shop,index) in shops" @click="adzhi(index)">
          <div><span>{{shop.username}}</span> {{shop.shouji}} <strong @click="remshan(index)">删 除</strong></div>
          <p>{{shop.sheng}}</p>
          <p>{{shop.sheng}}{{shop.dizhi}}</p>
        </li>
      </ul>
    </div>
    <button @click.prevent="isShow = !isShow">新 建 地 址</button>
    <transition name="slide">
      <footer v-if="isShow">
        <div class="zhi-top">
          <span @click="isShow = !isShow">X</span> 新增地址
        </div>
        <form action="">
          <div>
            收货人:
            <input type="text" v-model="datas.username" placeholder="收货人姓名"> 
          </div>
          <div>
            手机号:
            <input type="text" v-model="datas.shouji" placeholder="手机号">
          </div>
          <div>
            所在地区:
            <input type="text" v-model="datas.sheng" placeholder="省 市 区">
          </div>
          <div>
            详细地址:
            <input type="text" v-model="datas.dizhi" placeholder="详细地址">
          </div>
          <div>
            设置为默认地址:
            <input type="checkbox" v-model="datas.isDizhi">
          </div>
          <button @click.prevent="adddizhi">确认添加</button>
        </form>
      </footer>
    </transition>
  </div>
</template>
<script>
  import axios from 'axios'
  export default {

    data: function () {
      return {
        isShow: false,
        datas:{},
        shops:'',
      }
    },
    mounted:function(){
      var that = this;
      axios.get('los/adddizhi',{shop:that.data}).then((resData)=>{
            console.log(resData)
            that.shops =resData.data.message;
        }).catch((error)=>{
            console.log(error);
        })
    },
    methods: {
      adddizhi:function(){
        var that = this;
        console.log('that.data');
        console.log(that.datas);
        axios.post('los/adddizhi',{shop:that.datas}).then((resData)=>{
            alert('添加成功');
            location.reload();
        }).catch((error)=>{
            console.log(error);
        })
      },
      remshan:function(index){
        // console.log(index)
        axios.post('los/remshan',{ins:index}).then((resData)=>{
            alert('删除成功');
            location.reload();
        }).catch((error)=>{
            console.log(error);
        })
      },
      adzhi:function(index){
        axios.post('los/adzhi',{ins:index}).then((resData)=>{
            location.href="/#/goumai";
        }).catch((error)=>{
            console.log(error);
        })
      }
    }
  }

</script>
<style scoped>
  footer {
      height: 403px;
    border-top: 1px solid #ccc;
    position: fixed;
    background: #fff;
    left: 0;
    right: 0;
    bottom: 0;
    color: #333;
  }
form > div{
  padding: 10px 10px;
  border-bottom: 1px solid #ccc;
}
input{
  border:none;
  margin-left: 10px;
}
form > button{
  width: 70%;
  margin: 60px 15% 30px;
  padding: 8px;
  border:none;
  box-shadow: 0 0 5px 0px #cc0000;
  background: #FA8072;
  color: #fff;
}
  .slide-enter {
    height: 0 !important;
  }

  .slide-enter-active {
    transition: all 0.7s;
  }

  .slide-leave-active {
    transition: all 0.7s;
  }

  .slide-leave-to {
    height: 0px !important;
  }

  .zhi-top {
    line-height: 45px;
    border-bottom: 1px solid #ccc;
    text-align: center;
    position: relative;
  }

  .zhi-top span {
    position: absolute;
    left: 10px;
  }

  .dizhi {
    margin-top: 50px;
    padding: 10px;
    color: #666;
  }

  .dizhi li {
    padding: 0 10px 10px;
    list-style: none;
    /*border: 1px solid #ccc;*/
    box-shadow: 0 0 3px 1px #ccc;
    border-radius: 5px;
    margin-bottom: 20px;
  }

  .dizhi li div {
    line-height: 45px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 5px;
    position: relative;
  }

  .dizhi li div span {
    margin-right: 20px;
  }

  .dizhi li div strong {
    position: absolute;
    right: 0;
  }

  .dizhi li p {
    font-size: 14px;
  }

  .hello>button {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border: 1px solid #FA8072;
    background: #FA8072;
    color: #fff;
    padding: 8px;
    font-size: 18px;
  }

  nav {
    padding: 0 15px;
    text-align: center;
    position: fixed;
    right: 0;
    left: 0;
    top: 0;
    z-index: 666;
    /*overflow: hidden;*/
    line-height: 45px;
    font-size: 16px;
    color: #fff;
    border-bottom: 1px solid #ccc;
    background: #FA8072;
  }

  nav>a {
    font-size: 30px;
    color: #fff;
  }

  .nav-zuo {
    float: left;
    margin-top: -2px;
  }
</style>